/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cardarus.operatingsystem.struts.actions;

import com.cardarus.operatingsystem.domain.Customer;
import com.cardarus.operatingsystem.domain.SalesTransaction;
import com.cardarus.operatingsystem.domain.SalesTransactionRow;
import com.cardarus.operatingsystem.model.BusinessModel;
import com.cardarus.operatingsystem.struts.forms.CheckoutForm;
import java.util.ArrayList;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Creates a new SalesTransaction.
 * This action is called from the Struts framework.
 * 
 * @author Javier Snaider
 */
public class CheckoutAction extends org.apache.struts.action.Action {

    /**
     * This action is called from the Struts framework.
     *
     * Creates a new SalesTransaction.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        ActionErrors errors = new ActionErrors();
        HttpSession session = request.getSession();

        SalesTransaction sale = (SalesTransaction) session.getAttribute("sale");

        if (sale == null) {
            sale = new SalesTransaction();
            sale.setRows(new ArrayList<SalesTransactionRow>());
            sale.setDate(new Date());
            session.setAttribute("sale", sale);
        }
        return mapping.findForward("success");
    }
}
